package com.leetcode;

/**
 * 942. 增减字符串匹配
 *
 * @author fy
 * @date 2022-05-09 20:36
 */
public class Solution942 {

    public int[] diStringMatch(String s) {
        if (s == null) {
            throw new RuntimeException("wrong s");
        }
        int n = s.length();
        int low = 0;
        int high = n;
        int[] perm = new int[n + 1];
        for (int i = 0; i < n; i++) {
            perm[i] = s.charAt(i) == 'I' ? low++ : high--;
        }
        // 最后一个，此时low == high
        perm[n] = low;
        return perm;
    }

}
